#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "Cockroach.h"
#include "MoveCockroach.h"
#include "Config.h"
#include "StunImpediments.h"
USING_NS_CC;


class HelloWorld : public cocos2d::CCLayer
{
private:
	bool enableMusic;

	int isGameOver;

	int countGameOver;
	/// 
	/// vibrate and broken
	/// 
	/// rung va vo nat
	/// 
	///
	/// @author
	/// time_create
	/// time_end:
	///
	void fVibrateAndBroken(StunImpediments* impediment);
	
	/// 
	/// base screen
	/// 
	/// can chinh lai hinh nen sau khi thuc hien thao tac rung
	/// 
	///
	/// @author
	/// time_create
	/// time_end:
	///
	void fBaseScreen();

	/// 
	/// shock and broken
	/// 
	/// choang khi vat can bi vo nat
	/// 
	///
	/// @author
	/// time_create
	/// time_end:
	///
	void fShockAndBroken(StunImpediments* impediment);

	/// 
	/// add impediments
	/// 
	/// them impediments vao chuong trinh
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	void fAddImpediments(CCPoint point);

	/// 
	/// add list stunimpediments
	/// 
	/// them danh sach stunimpediments vao chuong trinh
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	void fAddListImpediments();

	/// 
	/// random position cho impediment
	/// 
	/// random vi tri xuat hien cua tung vat can
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	int* fRandomPosition();

	/// 
	/// add position to list impediment
	/// 
	/// them vi tri vua random vao cho tung vat can
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	void fAddPositionToListImpediments();

	/// 
	/// random time appear
	/// 
	/// random thoi gian xuat hien cua vat can (bao nhieu day thi xuat hien)
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	void fRandomTimeDisAppear();

	/// 
	/// display impediment
	/// 
	/// hien thi vat can voi thoi gian kImpedimentTimeBeforeAppear
	/// 
	///
	/// @author: hoang kim
	/// time_create
	/// time_end:
	///
	void fDisplayImpediments(float delta);	
	
	CCArray* listImpediment; // mang chua vat can
	StunImpediments* mImpediment; //bien kieu mstunimpediments
	int mIsDie; // nguoi choi gameover
	int mImpedimentsIsAppear;//gia tri khoi tao su xuat hien cua impediment

	CCArray * listCockRoach; // danh sach gian

	GameState m_curentState; 

	int m_score;

	int m_escape;

	int mCockRoachDie;

	CCSize mSize; //kick thuoc man hinh

	// thoi gian dem nguoc de start game
	int countdown;

	int score;

	int life;

public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::CCScene* scene();
    
    // a selector callback
    void menuCloseCallback(CCObject* pSender);
    
    // implement the "static node()" method manually
    CREATE_FUNC(HelloWorld);
	virtual bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event);

	/// 
	/// CHU THICH SO LUOC VE HAM setLevel() va getLevel()
	/// THAM SO 1 CHO HAM : score
	/// 
	/// Ham set diem va get diem cua con gian
	///
	/// @author : Quach Van Quyet
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	inline void setScore(int score) {m_score = score;}
	inline int getScore() {return m_score;}

	/// 
	/// CHU THICH SO LUOC VE HAM setCockRoachEscepse()
	/// THAM SO 1 CHO HAM : state
	/// 
	/// Ham set trang thai cua Game : Bat dau, dang choi va ket thuc game
	/// Va tra ve trang thai cua con Game dang choi
	///
	/// @author : Quach Van Quyet
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	inline void setCockRoachEscape() {m_escape++;}


	/// 
	/// CHU THICH SO LUOC VE HAM setState() va getState()
	/// THAM SO 1 CHO HAM : state
	/// 
	/// Ham set trang thai cua Game : Bat dau, dang choi va ket thuc game
	/// Va tra ve trang thai cua con Game dang choi
	///
	/// @author : Quach Van Quyet
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	inline void setState(GameState state) {m_curentState = state;}
	inline int getState() {return m_curentState;}

	/// 
	/// CHU THICH SO LUOC VE HAM isCollision()
	/// THAM SO 1 CHO HAM : sp1
	/// THAM SO 2 CHO HAM : sp2
	/// THAM SO 3 CHO HAM : minSize
	/// 
	/// Ham kiem tra su kien cham vao con gian
	/// Neu cham trung thi tra ve : TRUE
	/// Neu cham khong trung thi tra ve : FALSE
	///
	/// @author : Quach Van Quyet
	/// time_create: 13/6/2014
	/// time_end: 13/6/2014
	///
	bool fIsCollision(CCSprite * sp1 , CCPoint * sp2 , int minSize);

	/// 
	/// CHU THICH SO LUOC VE HAM fIsCollisionWithArmature
	/// sp1 : Animation duoc khoi tao tu file .Json
	/// sp2 : Diem ma ngon tay cham vao
	/// THAM SO 3 CHO HAM : minSize
	/// 
	/// Ham kiem tra su kien cham cua cac vat the khi duoc bam
	/// Neu cham trung thi tra ve : TRUE
	/// Neu cham khong trung thi tra ve : FALSE
	///
	/// @author : Quach Van Quyet
	/// time_create: 13/6/2014
	/// time_end: 13/6/2014
	bool fIsCollisionWithArmature(CCNode * sp1 , CCPoint * sp2 , int minSize);


	/// 
	/// init value
	///
	/// @author : Quan HM
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	void fInitValue();


	/// 
	/// Khoi tao list gian va add cac doi tuong gian mac dinh vao screen
	///
	/// @author : Phuoc td
	/// time_create: 13/6/2014
	/// time_end: 13/6/2014
	///
	void fAddListCockroach();

	/// 
	/// Create UI label life
	///				[type]				[description]
	/// @param 1 : 	CCPoint				position of label
	/// @param 2 : 	char*				font name
	/// @param 3 : 	int					font size
	/// @param 4 : 	int 				life
	///	return 		CCLabelTTF | NULL	mix
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	CCLabelTTF* fAddLabelLife(CCPoint pos, char* fontName, int fontSize, int life);

	/// 
	/// Create UI label life
	///				[type]				[description]
	/// @param 1 : 	CCPoint				position of label
	/// @param 2 : 	char*				font name
	/// @param 3 : 	int					font size
	/// @param 4 : 	int 				life
	///	return 		CCLabelTTF | NULL	mix
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fAddLabelLife(CCLayer* parent, CCPoint pos, char* fontName, int fontSize, int life);

	/// 
	/// Update UI life
	///
	///				[type]				[description]
	///	@param 1 : 	CCLabelTTF*			label life
	/// @param 2 : 	int 				life
	///	return 		void | NULL
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fUpdateUILife(CCLabelTTF* lbLife, int life);

	/// Create UI life with image
	///				[type]			[description]
	/// @param 1	int				life play
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fCreateUIImageLife(int life);

	/// Create UI life with image
	///				[type]			[description]
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fCreateUIImageLife();

	/// 
	/// Update UI life
	///
	///				[type]				[description]
	///	@param 1 : 	CCLayer*			layer parent contain child
	///	return 		void | NULL
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 17 - 06 - 2014
	/// time_end: 17 - 06 - 2014
	///	version : 0.1
	void fUpdateUIImageLife(CCLayer* parent);

	/// remove image life
	///				[type]				[description]
	///	@param 1	CCLayer*			parent of image
	///	@param 2	int					tag of image
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 16 - 06 - 2014
	/// time_end: 16 - 06 - 2014
	///	version : 0.1
	void fRmoveImageLife(CCLayer* parent, int tagImageLife);

	/// update UI life image 
	///				[type]				[description]
	/// @param 1	CCLayer*			parent contain image life
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 16 - 06 - 2014
	/// time_end: 16 - 06 - 2014
	///	version : 0.1
	//void fUpdateUIImageLife(CCLayer* parent);

	/// 
	/// Create UI label score
	///				[type]				[description]
	/// @param 1 : 	CCPoint				position of label
	/// @param 2 : 	char*				font name
	/// @param 3 : 	int					font size
	/// @param 4 : 	int 				score
	///	return 		CCLabelTTF | NULL	mix
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	CCLabelTTF* fAddLabelScore(CCPoint pos, char* fontName, int fontSize, int score);

	/// 
	/// Create UI label score
	///				[type]				[description]
	/// @param 1 : 	CCLayer*			layer parent
	/// @param 2 : 	CCPoint				position of label
	/// @param 3 : 	char*				font name
	/// @param 4 : 	int					font size
	/// @param 5 : 	int 				score
	///	return 		void | NULL			mix
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fAddLabelScore(CCLayer* parent, CCPoint pos, char* fontName, int fontSize, int score);

	/// 
	/// Create UI label score
	///				[type]				[description]
	///	return 		void | NULL			mix
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fAddLabelScore();

	/// 
	/// Khoi tao man hinh dem nguoc luc bat dau vao game
	///
	/// @author : Quan HM
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	void fCreateOverlay(CCLayer* parent);

	/// 
	/// Go bo lop phu
	///
	/// @author : Quan HM
	/// time_create: 16/6/2014
	/// time_end: 16/6/2014
	///
	void fRemoveOverlay(float delta);


	/// 
	/// Create menu play again
	///
	///				[type]			[description]
	///	@param 1 : 	char*			path of file save best score
	///	return 		CCMenu* | NULL
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fCreatePanelGameOver(CCLayer* parent);

	/// 
	/// reset game
	///
	///				[type]			[description]
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 16 - 06 - 2014
	/// time_end: 16 - 06 - 2014
	///	version : 0.1
	void fResetGame(CCObject* pSender);

	/// 
	/// Update UI score
	///
	///				[type]				[description]
	///	@param 1 : 	CCLabelTTF*			label score
	/// @param 2 : 	int 				score
	///	return 		void | NULL
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fUpdateUIScore(CCLabelTTF* lbScore, int score);

	/// 
	/// Update UI score
	///
	///				[type]				[description]
	///	return 		void | NULL
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 13 - 06 - 2014
	/// time_end: 13 - 06 - 2014
	///	version : 0.1
	void fUpdateUIScore();



	/// 
	/// Add table image
	///
	///				[type]			[description]
	///
	/// CHU THICH CHI TIET VE HAM
	/// 
	///
	/// @author HMQUAN
	/// time_create: 16 - 06 - 2014
	/// time_end: 16 - 06 - 2014
	///	version : 0.1
	void fAddBackgroundTable();

	void fAddCockroach(int number);

	void rotate(float t);

	virtual void onEnter();
    virtual void onExit();

	virtual void update(float delta);

	void fStopAllAction();

	void hideAdsAdmob();
	
	void showAdsAdmob();

	void showMobparten();

	void musicController(CCObject* pSender);

	void topOnline(CCObject* sender);
};

#endif // __HELLOWORLD_SCENE_H__